<?php
use Workerman\Worker;
require_once __DIR__ . '/vendor/workerman/workerman/Autoloader.php';
Worker::$stdoutFile = '/tmp/stdout.log';
// 创建一个Worker监听2345端口，使用websocket协议通讯
$http_worker = new Worker("websocket://0.0.0.0:8090");

// 这里进程数必须设置为1
$http_worker->count = 1;
// 客户端发来消息时，广播给其它用户
$http_worker->onMessage = function($connection, $message)use($http_worker)
{
    foreach($http_worker->connections as $connection)
    {
        $connection->send($message);
    }
};

Worker::runAll();